//
//  MyViewController.m
//  UI14_豆瓣电影更新版
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "MyViewController.h"
#import "LoginViewController.h"
#import "MyActivityViewController.h"
#import "ActivityModel.h"
#import "dataBaseHandle.h"
@interface MyViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSArray *arr;
@property (nonatomic, copy) NSString *temp;
@end

@implementation MyViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)dealloc {
    [_label release];
    [_label2 release];
    [_label3 release];
    [_arr release];
    [_tableView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"我的";
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(item:)];
    item.tag = 1000;
    self.navigationItem.rightBarButtonItem = item;
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [_tableView release];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
   self.arr = @[@"我的活动", @"我的电影", @"清除缓存"];
    [self handel];
}
// item方法
- (void)item:(UIBarButtonItem *)item {
    LoginViewController *login = [[LoginViewController alloc] init];
    login.block = ^void(NSString *str) {
        UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:str style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
        self.navigationItem.rightBarButtonItem = item2;
    };
    [self.navigationController pushViewController:login animated:YES];
   
}
// 注销方法
- (void)itemAction:(UIBarButtonItem *)item {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否确认注销" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(item:)];
        self.navigationItem.rightBarButtonItem = item;
    }];
    [alert addAction:action];
    [alert addAction:action2];
    [self presentViewController:alert animated:YES completion:nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
       return cell;
}
// Cell点击
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        
        MyActivityViewController *my = [[MyActivityViewController alloc] init];
        
        my.str = _arr[indexPath.row];
        [self.navigationController pushViewController:my animated:YES];
        
        
    }
    else if (indexPath.row == 1) {
        
    }
    else if (indexPath.row == 2) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否清除缓存" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            // 清除缓存
            [[dataBaseHandle sharedDataBaseHandle]deleteAll];
        }];
        [alert addAction:action];
        [alert addAction:action2];
        [self presentViewController:alert animated:YES completion:^{
            }];
    }
        
    
    
}
// 数据处理
- (void)handel {
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
    [self.view addSubview:_label];
    _label.text = _arr[0];
    [_label release];
    self.label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 100, 30)];
    _label2.text = _arr[1];
    [self.view addSubview:_label2];
    [_label2 release];
    self.label3 = [[UILabel alloc] initWithFrame:CGRectMake(10, 90, 100, 30)];
    [self.view addSubview:_label3];
    _label3.text = _arr[2];
    [_label3 release];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
